package br.com.senac.pi5.servlet;

import br.com.senac.pi5.bean.Aeroporto;
import br.com.senac.pi5.dao.AeroportoDao;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "AeroportoServlet", urlPatterns = {"/AeroportoServlet"})
public class AeroportoServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");

        try {
            List<Aeroporto> aeroportos = new ArrayList<>();
            AeroportoDao dao = new AeroportoDao();

            aeroportos = dao.buscaTodosAeroportos();

            for (int i = 0; i < aeroportos.size(); i++) {
                System.out.println(aeroportos.get(i).getCidade() + " - " + aeroportos.get(i).getNome()
                );
            }
        } catch (SQLException ex) {
            Logger.getLogger(AeroportoServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
